$(function() {
	$("body").ajaxSuccess(function (o, xhr, property) {
		if(xhr.status=="200"){
				var result =JSON.parse(xhr.responseText);
				if(result.msgCode=="10001" || result.msgCode=="10002" || result.msgCode=="10003"){
					//window.location.href="../orgError.html?msg="+result.msg; 
					//window.top.location="../orgError.html?msg="+result.msg;
					window.parent.location.href="../orgError.html?msg="+escape(result.msg);
				}
		}
	});
	
	window.ctx=getContextPath();
	$(".dictCodeComboBox").each(function(){
		var dictCode=$(this).attr("dictCode");
		var dataId=$(this).attr("dataId");
		if(dictCode){
			var id=$(this).attr("id");
			$("#"+id).ligerComboBox({
				url:window.ctx + "/mvc/dicts/api/dictcode/getDictList.json?parentKey="+dictCode,
				valueField:"dictCode",
				textField:"dictCnName",
				valueFieldID:dataId,
				selectBoxHeight:"70px"
			});
		}
	});
	
	$(".attributeComboBox").each(function(){
		var parent=$(this).attr("parent");
		var attribute=$(this).attr("attribute");
		
		var url=window.ctx+"/mvc/attributetype/api/attributetype/listParentType.json";
		
		if(parent=="false"){
			url=window.ctx+"/mvc/attributetype/api/attributetype/querySubAttributeType.json?objectName="+attribute;
		}
		
		var dataId=$(this).attr("dataId");
		var id=$(this).attr("id");
		if(parent =="false" && (attribute == "" || attribute == null)){
			url="";
		}
		$("#"+id).ligerComboBox({
			url:url,
			valueField:"id",
			textField:"text",
			valueFieldID:dataId,
			selectBoxHeight:"70px"
		});
	});
	
/*	$(".easyui-combotree").each(function(){
		var dictCode=$(this).attr("dictCode");
		if(dictCode){
			$(this).combotree({
				url : window.ctx + '/common/dict/controller/dict/treeAllDict.json?dictCode='+dictCode,
				onBeforeSelect: function(node) {            
					if (!$(this).tree('isLeaf', node.target)) { 
						return false;
					}        
				}
			});
		}
	});*/
});

function getContextPath() {
    var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("/");
    var result = pathName.substr(0,index+1);
    return result;
}

function textTrim(str) {  
    return str.replace(/\s+/g,"");  
}

// 百分比比例
function getHeight(percent) {
	return $(window).height() * percent;
}

function getWidth(percent) {
	return $(window).width() * percent;
}

function checkDate(start, end) {
	var checkStartDate = start;// 开始日期
	var checkEndDate = end;// 结束日期
	var arys = new Array();
	var arys1 = new Array();
	var arys2 = new Array();
	if (checkStartDate != null && checkEndDate != null) {
		arys = checkStartDate.split('-');
		arys1 = arys[2].split(' ');
		arys2 = arys1[1].replace(/(^\s*)|(\s*$)/g, "").split(":");// 时间部分去空格并且按照':'分割
		var startdate = new Date(arys[0], parseInt(arys[1] - 1), arys1[0],
				arys2[0], arys2[1], arys2[2]);// 重新new 一个Date
		arys = checkEndDate.split('-');
		arys1 = arys[2].split(' ');
		arys2 = arys1[1].replace(/(^\s*)|(\s*$)/g, "").split(":");
		var checkEndDate = new Date(arys[0], parseInt(arys[1] - 1), arys1[0],
				arys2[0], arys2[1], arys2[2]);
		if (startdate < checkEndDate) {
			// alert("日期开始时间大于结束时间");
			return true;
		} else {
			return false;
		}
	}
}